package com.scholarship.modules.backend.controller;

import com.scholarship.common.entity.RetCode;
import com.scholarship.common.entity.RetResponse;
import com.scholarship.common.entity.RetResult;
import com.scholarship.modules.backend.entity.RewardTypeDetail;
import com.scholarship.modules.backend.service.RewardTypeDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhz
 * @date 2021/5/10 20:06
 * 备注：针对奖学金具体加分项表的增删改查
 */
@Api(tags = {"奖学金具体加分项表的增删改查"})
@RestController
public class RewardTypeDetailController {
    @Autowired
    RewardTypeDetailService rewardTypeDetailService;

    @ApiOperation("获取所有学金具体加分项 @author zhz")
    @GetMapping("/admin/ListRewardTypeDetail")
    public RetResult listRewardTypeDetail(){
        return RetResponse.makeRsp(RetCode.SUCCESS,"成功展示所有奖学金具体加分项信息",rewardTypeDetailService.listRewardTypeDetail());
    }
    @ApiOperation("添加学金具体加分项 @author zhz")
    @PostMapping("/admin/addRewardTypeDetail")
    public RetResult addRewardTypeDetail(@RequestBody RewardTypeDetail rewardTypeDetail){
        if(rewardTypeDetailService.addRewardTypeDetail(rewardTypeDetail)==-1){
            return RetResponse.makeRsp(RetCode.SUCCESS,"必填字段没有填写");
        }else return RetResponse.makeRsp(RetCode.SUCCESS,"成功添加奖学金具体加分项信息");
    }
    @ApiOperation("修改某个学金具体加分项 @author zhz")
    @PostMapping("/admin/updateRewardTypeDetail")
    public RetResult updateRewardTypeDetail(@RequestBody RewardTypeDetail rewardTypeDetail){
        Integer result = rewardTypeDetailService.updateRewardTypeDetail(rewardTypeDetail);
        if(result==-1){
           return RetResponse.makeRsp(RetCode.FAIL,"id不存在");
        }else{
            return RetResponse.makeRsp(RetCode.SUCCESS,"成功修改了id为："+rewardTypeDetail.getId()+"的"+result+"行数据");
        }
    }
    @ApiOperation("删除某个学金具体加分项 @author zhz")
    @PostMapping("/admin/deleteRewardTypeDetail")
    public RetResult deleteRewardTypeDetail(@RequestBody RewardTypeDetail rewardTypeDetail){
        Integer result = rewardTypeDetailService.deleteRewardTypeDetail(rewardTypeDetail);
        if(result==-1){
            return RetResponse.makeRsp(RetCode.FAIL,"id不存在");
        }else{
            return RetResponse.makeRsp(RetCode.SUCCESS,"成功删除了id为："+rewardTypeDetail.getId()+"的"+result+"行数据");
        }
    }
}
